package org.ghost.wechat.platform.dao;

import org.ghost.wechat.platform.common.http.annotation.HttpClientEx;
import org.ghost.wechat.platform.common.http.annotation.RequestMappingEx;
import org.ghost.wechat.platform.dto.wechat.base.WeChatAccessTokenRspDTO;
import org.ghost.wechat.platform.dto.wechat.base.WeChatCallbackIpRspDTO;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 01
 */
@HttpClientEx(hostName = "https://api.weixin.qq.com")
public interface IWeChatBaseDAO {
    /**
     * 获取其他接口调用需要的access_token
     * https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
     * 40001	AppSecret错误或者AppSecret不属于这个公众号，请开发者确认AppSecret的正确性
     * 40002	请确保grant_type字段值为client_credential
     * 40164	调用接口的IP地址不在白名单中，请在接口IP白名单中进行设置。（小程序及小游戏调用不要求IP地址在白名单内。）
     *
     * @param appId     第三方用户唯一凭证
     * @param secret    第三方用户唯一凭证密钥，即appsecret
     * @param grantType 获取access_token填写client_credential
     * @return
     */
    @RequestMappingEx(name = "cgi-bin/token", method = HttpMethod.GET)
    WeChatAccessTokenRspDTO getAccessToken(@RequestParam(value = "appid") String appId,
                                           @RequestParam(value = "secret") String secret,
                                           @RequestParam(value = "grant_type") String grantType);

    /**
     * 获取微信callback IP地址,callback IP即微信调用开发者服务器所使用的出口IP
     * https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_the_WeChat_server_IP_address.html
     *
     * @param accessToken 公众号的access_token
     * @return
     */
    @RequestMappingEx(name = "cgi-bin/getcallbackip", method = HttpMethod.GET)
    WeChatCallbackIpRspDTO getCallbackIp(@RequestParam(value = "access_token") String accessToken);

    /**
     * 获取微信API接口 IP地址,API接口IP即api.weixin.qq.com的解析地址，由开发者调用微信侧的接入IP
     * https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_the_WeChat_server_IP_address.html
     *
     * @param accessToken 公众号的access_token
     * @return
     */
    @RequestMappingEx(name = "cgi-bin/get_api_domain_ip", method = HttpMethod.GET)
    WeChatCallbackIpRspDTO getApiDomainIp(@RequestParam(value = "access_token") String accessToken);
}
